<template>
  <div>
    <el-dialog
      title="拖动地图选取址"
      :visible.sync="stationcard"
      width="45%"
      :before-close="close"
    >
      <el-form ref="form" :model="stationobject" label-width="80px">
        
        <el-form-item label="站点地址">
          <el-select
            v-model="logisticsStationAddress"
            placeholder="请选择公司地址"
            style="width: 50ex"
          >
            <el-option
              v-for="(item, index) in addressArray"
              :key="item + index"
              :label="item.address + item.title"
              :value="item.address + item.title"
              @click.native="setcoordinates(item.location)"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <Map
          :selectedLocation="location"
          @getCenterAddress="setAddress"
          @getAroundPoi="setpoi"
        >
        </Map>

        <el-form-item style="right">
            <el-button @click="close">确定</el-button>
          <el-button @click="close">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import Map from "../../components/OrderManagement/MyLocationPicker"
export default {
      components: {
            Map,
        },
  props: {
    stationcard: {
      type: Boolean,
    },
    stationData: {
      type: Object,
    },
  },
   data() {
    return {
      // 地图传来的地址数组
      addressArray: [],
      // 传入地图的中心坐标
      location: {
        lat: "",
        lng: "",
      },
      // --------列表数据-------
        // 接收地址
        logisticsStationAddress: "",  
    };
  },
  methods: {
    // 关闭时设置为空
    setclose() {
      this.logisticsStationAddress = "";
    },
    // 设置坐标
    setcoordinates(location) {
      this.location = location;
      console.log("customerlocation-->", this.location);
    },
    // 关闭表单
    close() {
      this.$emit("closed",this.logisticsStationAddress);
      this.setclose();
    },
    // 设置地图返回的定点位置
    setAddress(address) {
      console.log("address2-->", address);
      this.logisticsStationAddress = address;
    },
    // 设置地图返回的位置数组并把坐标设置好
    setpoi(poi) {
      console.log("pio-->", poi);
      this.addressArray = poi;
    },
  }
}
</script>